#!/bin/sh
# don't start this script as root, run as a normal user. We need to run some actions as $USER, and others as root.
#  
numargs=$#
this_script=$0
username=$1

. ./source_me
echo "numargs = $numargs"

if [ "$numargs" = 0 ]; then
  username=$USER
  echo "re-running script as root..."
  sudo ./$this_script $USER # re-run this script as root, passing in the username of the original caller
  echo "finished running as root."
  exit $?
fi

required_packages="build-essential perl python git "^libxcb.*" libx11-xcb-dev libglu1-mesa-dev libxrender-dev flex bison gperf libicu-dev libxslt-dev ruby libasound2-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libpq5 libpq-dev libboost-serialization1.48 postgresql-client-9.1"
optional_packages="synaptic cscope openssh-server"

apt-get install -y $required_packages $optional_packages
if [ "$?" -ne 0 ]; then
  exit $?
fi

sudo -u $username mkdir -p $BASE_DIR
cd $BASE_DIR/openmining

# qt5
########################################################################################################
./setup_qt5 $username

# qt3d
########################################################################################################
./setup_qt3d $username

# qwtplot3d
########################################################################################################
./setup_qwtplot3d $username

# openmining
########################################################################################################
./setup_openmining $username


